package com.danci.controller;


import com.danci.common.Result;
import com.danci.dto.LearnWordDto;
import com.danci.dto.UserRequest;
import com.danci.service.impl.WordsServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * <p>
 * 单词表 前端控制器
 * </p>
 *
 * @author xxx
 * @since 2024-05-13
 */
@RestController
@RequestMapping("/words")
@AllArgsConstructor
@Api("单词操作")
public class WordsController {
    private final WordsServiceImpl wordsService;

    @ApiOperation("初始化、不用管这个接口")
    @GetMapping("/init")
    public void initWords(){
        wordsService.initWords();
    }

    @ApiOperation("词库导入")
    @PostMapping("/import")
    public Result importWords(MultipartFile file,@RequestParam(value = "lid",required = true)String lid) throws IOException {
        return wordsService.importWords(file,lid);
    }

    @ApiOperation("学习接口")
    @PostMapping("/learn")
    public Result learn(@RequestBody LearnWordDto learnWordDto){
        return wordsService.learn(learnWordDto);
    }

    @ApiOperation("单词推荐")
    @PostMapping("/recommend")
    public Result recommend(@RequestBody UserRequest userRequest){
        return wordsService.recommend(userRequest);
    }
}
